import request from "@/common/utils/request";
import { createVNode, h } from "vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import { message, Modal } from "ant-design-vue";
export function getComputingPowerDetail(data = {}) {
  const { number = 1, init = false, key = 'extract_video_link_point' } = data;
  return new Promise(async (resolve, reject) => {
    const res = await request.get(
      "/work_ai",
      "/user/shotstack/video/conver/text/config",
      {
        number,
        key,
      }
    );
    resolve(res);
  });
}

export const languageList = [
  {
    label: "中文",
    value: "zh",
    target: true,
  },
  {
    label: "中文-繁体",
    value: "zh-tw",
  },
  {
    label: "印度尼西亚语",
    value: "id",
  },
  {
    label: "英文",
    value: "en",
    target: true,
  },
  {
    label: "日文",
    value: "ja",
  },
  {
    label: "韩文",
    value: "ko",
  },
  {
    label: "法文",
    value: "fr",
  },
  {
    label: "西班牙文",
    value: "es",
  },
  {
    label: "葡萄牙语",
    value: "pt",
  },
  {
    label: "土耳其语",
    value: "tr",
  },
  {
    label: "阿拉伯语",
    value: "ar",

  },
  {
    label: "粤语",
    value: "yue",

  },
  {
    label: "俄语",
    value: "ru",

  },
  {
    label: "泰语",
    value: "th",

  },
  {
    label: "越南语",
    value: "vi",

  },
  {
    label: "马来语",
    value: "ms",

  },
];

export const platformList = ['抖音', '小红书']

// 获取消耗提示词
export function useTextToH(params) {
  const useName = params.numberInfo.name;
  const icon = h(ExclamationCircleOutlined);
  const span = h('span', {
    style: 'margin-left: 5px;'
  }, `${useName?useName:params.title}会有失败的情况，若失败会返还对应的${params.pointInfo.name}`);
  const tipDiv = h('div', {
    style: 'display: flex; align-items: center; padding: 10px;margin-top:15px;background: #e8f5f0;border-radius: 4px;color: #479a7a;'
  }, [icon, span]);

  let coastPoint = params.durtion?params.pointInfo.consumes * params.durtion:params.pointInfo.consumes
  
  const contentDiv = h('div', { style: 'margin-top:10px;' }, [
    '当前剩余',
    h('span', { style: 'color: var(--ss-primary-color)' }, params.pointInfo?.current),
    params.pointInfo.unit,
    params.pointInfo.name,
    '，本次',
    useName,
    '将消耗',
    h('span', { style: 'color:var(--ss-primary-color)' },coastPoint ),
    params.pointInfo.unit,
    params.pointInfo.name
  ]);

  return { tip: tipDiv, content: contentDiv }
}
let isModalPending = false; // 用于标记是否有模态框正在处理中
export function useModal(params) {
  const { title = "提示", content = {}, ok = null, res = {}, loading = false } = params;

  // 如果已经有模态框在处理中，直接返回
  if (isModalPending) {
   return 
  }

  return new Promise((resolve, reject) => {
    if (res?.pointInfo?.consumes <= 0) {
      resolve('ok');
      return;
    }

    // 标记为有模态框正在处理中
    isModalPending = true;

    Modal.confirm({
      okText: "确定",
      cancelText: "取消",
      title,
      width: 460,
      confirmLoading: params.loading,
      icon: null,
      zIndex: 9999,
      bodyStyle: {
        padding: "20px",
      },
      content: h("div", {}, [content.tip, content.content]),
      onOk() {
        // 重置标记
        isModalPending = false;
        resolve("ok");
      },
      onCancel() {
        // 重置标记
        isModalPending = false;
        reject("cancel");
      },
    });
  });
}
// 获取视频时长
export const getVideoDuration = (videoPath) => {
  return new Promise((resolve, reject) => {
    const video = document.createElement("video");
    video.src = videoPath;
    video.addEventListener("loadedmetadata", () => {
      const duration = video.duration;
      resolve(duration);
    });
  });
};
// 获取抖音分享链接视频时长
export const getVideoUrlTime = (video_url) => {
  return new Promise(async (resolve, reject) => {
    const res = await request.post(
      "/work_ai",
      "/user/shotstack/video/get_time",
      {
        video_url,
      }
    );
    resolve(res);
  });
}